package com.bidevalution.controller.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bidevalution.business.service.BeRoomDeviceService;
import com.bidevalution.business.service.BeRoomService;
import com.bidevalution.business.service.BeSectionInfoService;
import com.bidevalution.dao.entity.BeRoom;
import com.bidevalution.dao.entity.BeRoomDevice;
import com.bidevalution.dao.entity.BeSectionInfo;
import com.qtp.common.core.TSUser;
import com.qtp.core.model.Response;

@RestController
@RequestMapping("/roomdevice")
public class BeRoomDeviceController {
	@Autowired
	private BeRoomService beRoomService;
	@Autowired
	private BeRoomDeviceService beRoomDeviceService;
	@Autowired
	private BeSectionInfoService beSectionInfoService;
	@RequestMapping(value = "/getopenurl", method = RequestMethod.GET)
	public Response<String> getOpenUrl( @RequestParam("sectionId") String sectionId) {
		BeSectionInfo beSectionInfo = beSectionInfoService.getBeSectionInfoById(sectionId);
		if(beSectionInfo != null) {
			BeRoom beRoom = beRoomService.selectByName(beSectionInfo.getBidOpenAddress());
			if(beRoom != null) {
				List<BeRoomDevice> beRoomDeviceList = beRoomDeviceService.selectByRoomId(beRoom.getId());
				if(beRoomDeviceList.size()>0) {
					BeRoomDevice beRoomDevice = beRoomDeviceList.get(0);
					return Response.ok(beRoomDevice.getOpenDomainName()+"/"+beRoomDevice.getAppName()+"/"+beRoomDevice.getStreamName());
				}
			}
		}
		return Response.fail("直播url不存在");
	}
}
